<?php

class Backend_PostController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        $objPost = new Application_Model_Posts();
        $arrPostList = $objPost->getPostList();
        $this->view->assign('arrPostList', $arrPostList);
    }

    public function createAction() {
        if ($this->getRequest()->getMethod() == 'POST') {

            $arrPost = $this->getParam('Post', array());
            $current = new Application_Model_DateTime();
            $arrPost['create_time'] = $current->getCurrent();
            $objPost = new Application_Model_Posts();
            $objPost->createPost($arrPost);
            $this->_helper->redirector('index', 'post');
        }
    }

    public function editAction() {
        if ($this->getRequest()->getMethod() == 'POST') {
            $intID = $this->getParam('id', 0);
            $arrPost = $this->getParam('Post', array());
            $current = new Application_Model_DateTime();
            $arrPost['update_time'] = $current->getCurrent();
            $objPost = new Application_Model_Posts();
            $objPost->editPost($intID, $arrPost);
            $this->_helper->redirector('index', 'post');
        } else {
            $intID = $this->getParam('id', 0);
            $objPost = new Application_Model_Posts();
            $arrPost = $objPost->getDetailPost($intID);
            $this->view->assign('arrPost', $arrPost);
        }
    }

    public function deleteAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        $intID = $this->getParam('id', 0);
        $objPost = new Application_Model_Posts();
        $objPost->deletePost($intID);
        $this->_helper->redirector('index', 'post');
    }

}
